package com.conceal.client.utils;
import java.util.Hashtable;
public class JsonResponse {
    private int resultCode=0;  // 结果代码
    private String state="OK";  // 结果状态，按逾期执行为OK，否则为ERR:XXXX，XXXX表示错误原因
    private String error="";  // 错误附加信息
    private Object data;  // 数据
    private Long pos;  // 分页位置
    private Long total_count;  // 记录数

    public JsonResponse(){
    }

    public JsonResponse(Object data){
        this.resultCode=0;
        this.state="OK";
        this.data=data;
    }

    public JsonResponse(int resultCode, Object data){
        this.resultCode=resultCode;
        this.state=resultCode==0 ? "OK" : ""+resultCode;
        this.data=data;
    }

    public JsonResponse(Object[] nameAndValue){
        this.resultCode=0;
        this.state="OK";
        Hashtable<Object, Object> data=new Hashtable<Object, Object>();
        for(int i=0; i<nameAndValue.length/2; i++){
            Object value=nameAndValue[i*2+1];
            if(value!=null){
                data.put(nameAndValue[i*2], nameAndValue[i*2+1]);
            }
        }
        this.data=data;
    }

    public String getError() {
        return error;
    }
    public void setError(String error) {
        this.error = error;
    }
    public Object getData() {
        return data;
    }
    public void setData(Object data) {
        this.data = data;
    }

    public void setData(Object...keyAndValue){
        Hashtable<String, Object> data=new Hashtable<String, Object>();
        for(int i=0; i<keyAndValue.length/2; i++){
            Object value=keyAndValue[i*2+1];
            data.put(keyAndValue[i*2].toString(), value==null?"":value);
        }
        this.data=data;
    }

    public int getResultCode() {
        return resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }

    public Long getPos() {
        return pos;
    }

    public void setPos(Long pos) {
        this.pos = pos;
    }

    public Long getTotal_count() {
        return total_count;
    }

    public void setTotal_count(Long total_count) {
        this.total_count = total_count;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

}
